

close all;
% compareResults('magic_kooi_05-04_15:24.csv', 'no-magic_kooi_05-04_15:17.csv', 'Epistemagic, Kooi''s choice', 'No epistemagic, Kooi''s choice');
% compareResults('magic_05-04_15:19.csv', 'no-magic_05-04_14:43.csv', 'Epistemagic', 'No epistemagic');
% compareResults('magic_kooi_inf_05-04_16:32.csv', 'no-magic_kooi_05-04_15:17.csv', 'Infinite epistemagic, Kooi''s choice', 'No epistemagic, Kooi''s choice');
% compareResults('magic_kooi_inf_05-04_16:32.csv', 'magic_kooi_05-04_15:24.csv', 'Infite epistemagic, Kooi''s choice', 'Epistemagic, Kooi''s choice');
% compareResults('magic_inf_05-04_15:24.csv', 'magic_05-04_15:19.csv', 'Infite epistemagic', 'Epistemagic');

magic = csvread('magic_05-04_15:19.csv');
noMagic = csvread('no-magic_05-04_14:43.csv');
magicInf = csvread('magic_inf_05-04_15:24.csv');

magicKooi = csvread('magic_kooi_05-04_15:24.csv');
magicKooiFull = csvread('magic_kooi_full_05-04_16:32.csv');
magicKooiInf = csvread('magic_kooi_inf_05-04_16:32.csv');
magicKooiFullInf = csvread('magic_kooi_inf_full_05-04_17:42.csv');
noMagicKooi = csvread('no-magic_kooi_05-04_15:17.csv');
noMagicKooiFull = csvread('no-magic_kooi_full_06-04_12:08.csv');

indices = (magic(:,5) ~= 0) & (noMagic(:,5) ~= 0) & (magicInf(:,5) ~= 0) & ...
    (magicKooi(:,5) ~= 0) & (magicKooiFull(:,5) ~= 0) & ...
    (magicKooiInf(:,5) ~= 0) & (magicKooiFullInf(:,5) ~= 0) & ...
    (noMagicKooi(:,5) ~= 0) & (noMagicKooiFull(:,5) ~= 0);



finishedGames(magic)
finishedGames(magicInf)
finishedGames(noMagic)
finishedGames(magicKooi)
finishedGames(magicKooiInf)
finishedGames(noMagicKooi)
finishedGames(magicKooiFull)
finishedGames(magicKooiFullInf)
finishedGames(noMagicKooiFull)

all = [];

allStd = [];

all = [all mean(magic(indices,5))];
all = [all mean(magicInf(indices,5))];
all = [all mean(noMagic(indices,5))];

all = [magic(indices,5) magicInf(indices,5) noMagic(indices,5) ...
    magicKooi(indices,5) magicKooiInf(indices,5) noMagicKooi(indices,5) ...
    magicKooiFull(indices,5) magicKooiFullInf(indices,5) ...
    noMagicKooiFull(indices,5)];

mean(all,1);
std(all,1);

allPlayerData = cat(3, magic(indices, 2:4), magicInf(indices, 2:4), ...
    noMagic(indices, 2:4), magicKooi(indices, 2:4), ...
    magicKooiInf(indices, 2:4), noMagicKooi(indices, 2:4), ...
    magicKooiFull(indices, 2:4), magicKooiFullInf(indices, 2:4), ...
    noMagicKooiFull(indices, 2:4));

winners = cat(2, magic(indices, 1), magicInf(indices, 1), ...
    noMagic(indices, 1), magicKooi(indices, 1), ...
    magicKooiInf(indices, 1), noMagicKooi(indices, 1), ...
    magicKooiFull(indices, 1), magicKooiFullInf(indices, 1), ...
    noMagicKooiFull(indices, 1));

meanWinners = mean(winners,1);

means = mean(allPlayerData, 1);

players = reshape(mean(allPlayerData, 1), 3, 9, 1)';


bar(players(1:6,:));
colormap summer


labels = {'Epistemagic', 'Infinite epistemagic', 'No epistemagic', 'KC: Epistemagic', ...
    'KC: Infinite epistemagic', 'KC: No epistemagic'}

set(gca(),'XTickLabel',labels)
%set(gca,'position',[0.13 0.35 0.775 0.55])
%rotateticklabel(gca, 45)
rotateXLabels(gca(), 45)
legend('PLAYER 1', 'PLAYER 2', 'PLAYER 3', 'Location', 'NorthWest');
title('Distribution of winning players')
ylabel('Percentage of games won')
axis([0.5 6.5 0 0.65])


means = mean(all,1)
means = reshape(means,3,3);
stds = std(all,1)

colors = size(all,2) * 2;

cc = hsv(colors);

figure,
cc(1)
for i = 1:3
    bar(i,means(i),'facecolor',cc(i,:)) 
    hold on;
end

for i = 4:6
    bar(i,means(i),'facecolor',cc(i + colors / 2,:))
    set(gca, 'XTick', []);
    hold on;
end

legend('Epistemagic', 'Infinite epistemagic', 'No epistemagic', ...
    'KC: Epistemagic', 'KC: Infinite epistemagic', 'KC: No epistemagic', ...
    'Location', 'NorthWest');

title('Average number of turns before game finishes');
ylabel('Turns');